
function BaseStyle(type)
{ 
  if(this.styleType == null)
    this.styleType = Array();

  this.styleType.push(type);  
}

BaseStyle.prototype.clone = function ()
{
  var cloned = new Object();
  for(var i in this)
    if(this[i] instanceof Array)
      cloned[i] = this[i].slice(0);
    else if(this[i] instanceof Function)
      cloned[i] = this[i];
    else if(this[i] instanceof Object)
      cloned[i] = this[i].clone();
    else
      cloned[i] = this[i];
  
  return cloned;
}

BaseStyle.prototype.is = function (name)
{
  for(var i in this.styleType)
    if(this.styleType[i] == name)
      return true;
      
  return false;
}

function FillStyle(fillColour)
{
  BaseStyle.call(this,'Fill');
  
  if(fillColour)
    this.fillColour = fillColour;
}

FillStyle.inherit(BaseStyle);

FillStyle.prototype.setup = function (context)
{
  if(this.fillColour)
    context.fillStyle = this.fillColour.toString();  
}

FillStyle.prototype.use = function (context)
{
  if(this.fillColour)
    context.fill();
}

function StrokeStyle(strokeColour,strokeWidth,strokeCap,strokeJoin,strokeMiter)
{
  BaseStyle.call(this,'Line');

  if(strokeColour)
    this.strokeColour = strokeColour;  

  if(strokeWidth)    
    this.strokeWidth = strokeWidth;  
  
  if(strokeCap)
    this.strokeCap = strokeCap;
    
  if(strokeJoin)
    this.strokeJoin = strokeJoin;
    
  if(strokeMiter)
    this.strokeMiter = strokeMiter;  
}

StrokeStyle.inherit(BaseStyle);

StrokeStyle.prototype.setup = function (context)
{
  if(this.strokeColour)
    context.strokeStyle = this.strokeColour.toString();
    
  if(this.strokeWidth)  
    context.lineWidth = this.strokeWidth;
    
  if(this.strokeCap)
    context.lineCap = this.strokeCap;
  
  if(this.strokeJoin)
    context.lineJoin = this.strokeJoin;
  
  if(this.strokeMiter)
    context.miterLimit = this.strokeMiter;
}

StrokeStyle.prototype.use = function(context)
{
  if(this.strokeColour && this.strokeWidth)
    context.stroke();
}  

function FillStrokeStyle(fillColour,strokeColour,strokeWidth,strokeCap,strokeJoin,strokeMiter)
{
  FillStyle.call(this,fillColour);
  StrokeStyle.call(this,strokeColour,strokeWidth,strokeCap,strokeJoin,strokeMiter); 
}

FillStrokeStyle.inherit(FillStyle);
FillStrokeStyle.inherit(StrokeStyle);

FillStrokeStyle.prototype.setup = function (context)
{
  FillStyle.prototype.setup.call(this,context);
  StrokeStyle.prototype.setup.call(this,context);
}

FillStrokeStyle.prototype.use = function(context)
{
  FillStyle.prototype.use.call(this,context);
  StrokeStyle.prototype.use.call(this,context);
}

function BaseFontStyle(font, align, baseline)
{
  BaseStyle.call(this,'Font');
  
  if(font)
    this.font = font;
    
  if(align)
    this.align = align;
      
  if(baseline)
    this.baseline = baseline;  
}

BaseFontStyle.inherit(BaseStyle);

BaseFontStyle.prototype.setup = function (context)
{
  if(this.font)
    context.font = this.font;
    
  if(this.align)
    context.textAlign = this.align;
    
  if(this.baseline)
    context.textBaseline = this.baseline;
}

function FillFontStyle(fillColour,font, align, baseline)
{
  FillStyle.call(this,fillColour);
  BaseFontStyle.call(this,font, align, baseline);
}

FillFontStyle.inherit(FillStyle);
FillFontStyle.inherit(BaseFontStyle);

FillFontStyle.prototype.setup = function (context)
{
  FillStyle.prototype.setup.call(this,context);
  BaseFontStyle.prototype.setup.call(this,context);  
}

function StrokeFontStyle(strokeColour,strokeWidth,font,align,baseline,strokeCap,strokeJoin,strokeMiter)
{
  BaseFontStyle.call(this,font,align,baseline);
  StrokeStyle.call(this,strokeColour,strokeWidth,strokeCap,strokeJoin,strokeMiter);
}

StrokeFontStyle.inherit(BaseFontStyle);
StrokeFontStyle.inherit(StrokeStyle);

StrokeFontStyle.prototype.setup = function (context)
{
  BaseFontStyle.prototype.setup.call(this,context);
  StrokeStyle.prototype.setup.call(this,context);  
}

function BaseStyles()
{
  this.styles = Array();
}

BaseStyles.prototype.addStyle = function (name, style)
{
  this.styles[name] = style;
}

BaseStyles.prototype.getStyle = function (name)
{
  if(name instanceof Object)
    return name;
    
  return this.styles[name];
}

BaseStyles.prototype.clearStyles = function ()
{
  this.styles = Array();
}

